#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/gpio.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/regs-gpio.h>
#include <linux/hardware.h>

#define DEVICE_NAME     "MQ_led"


static unsigned long led_table[]={
	S5P4418_GPB(5),
	S5P4418_GPB(6),
	S5P4418_GPB(7),
	S5P4418_GPB(8),
}

static unsigned int led_cfg_table[]={
	S5P4418_GPIO_OUTPUT,
	S5P4418_GPIO_OUTPUT,
	S5P4418_GPIO_OUTPUT,
	S5P4418_GPIO_OUTPUT,
}

static int MQ_led_ioctl(struct inode* inode,file* file,unsigned int cmd,unsigned long arg)
{
	if(arg<0||arg>3)
	{
		return -EINVAL;
	}
	switch(cmd)
	{
		case 0:
		case 1:
		{
			s3c2410_gpio_setpin(led_table[arg],!cmd);
			return 0;
		}
		default:
			return -EINVAL;
	}
}


static struct file_operations dev_fops={
	.owner=THIS_MODULE,
	.ioctl=MQ_led_ioctl,
};

static struct miscdevice misc={
	.minor=MISC_DYNAMIC_MINOR,
	.name=DEVICE_NAME,
	.fops=&dev_fops,
};

static int __init led_init(void)
{
	int ret;
	int i;
	for(i=0;i<4;i++)
	{
		s3c2410_gpio_cfgpin(led_table[i],led_cfg_table[i]);
		s3c2410_gpio_cfgpin(led_table[i],0);
		
	}
}

static void __exit led_exit(void)
{
	msic_deregister(&misc);
}

module_init(led_init);
module_exit(led_exit);
MODULE_LICENSE("GPL");
